﻿using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;

namespace DotNet.DevOps.Tasks.Tests.Extensions
{
    internal static class AssemblyInfoTestExtensions
    {
        internal static void AssertThatFileMatchesTask(this String filename, AssemblyInfo.AssemblyInfo asm)
        {
            var expectedEntries = asm.GetExpectedNonRequiredStringPropertyEntries();

            var fileContent = File.ReadAllText(filename);

            expectedEntries.ForEach(entry => Assert.That(fileContent.Contains(entry), Is.True, String.Format("{0} not found in {1}.", entry, fileContent)));
        }

        internal static void AssertThatFileHasMissingFields(this String filename, List<String> fieldnames)
        {
            var fileContent = File.ReadAllText(filename);

            fieldnames.ForEach(entry => Assert.That(fileContent.Contains(entry), Is.False, String.Format("{0} found but should be missing in {1}.", entry, fileContent)));
        }

        internal static void AssertThatFileHasEntryWithValue(this String filename, String entry)
        {
            var fileContent = File.ReadAllText(filename);

            Assert.That(fileContent.Contains(entry), Is.True);
        }
    }
}
